SUBDIRS = autoload

scmdatadir = $(LEPTONDATADIR)/scheme
godir = $(LEPTONDATADIR)/ccache

nobase_dist_scmdata_DATA = \
	backend/PCB.scm \
	backend/allegro.scm \
	backend/bae.scm \
	backend/bom.scm \
	backend/bom2.scm \
	backend/calay.scm \
	backend/cascade.scm \
	backend/drc.scm \
	backend/drc2.scm \
	backend/eagle.scm \
	backend/ewnet.scm \
	backend/futurenet2.scm \
	backend/gossip.scm \
	backend/liquidpcb.scm \
	backend/makedepend.scm \
	backend/mathematica.scm \
	backend/maxascii.scm \
	backend/osmond.scm \
	backend/pads.scm \
	backend/partslist1.scm \
	backend/partslist2.scm \
	backend/partslist3.scm \
	backend/pcbpins.scm \
	backend/protelII.scm \
	backend/redac.scm \
	backend/spice-noqsi.scm \
	backend/spice-sdb.scm \
	backend/spice.scm \
	backend/spice/common.scm \
	backend/switcap.scm \
	backend/systemc.scm \
	backend/tango.scm \
	backend/tEDAx.scm \
	backend/vams.scm \
	backend/verilog.scm \
	backend/vhdl.scm \
	backend/vipec.scm \
	color-map.scm \
	conf/schematic/attribs.scm \
	conf/schematic/deprecated.scm \
	conf/schematic/keys.scm \
	conf/schematic/menu.scm \
	conf/schematic/stroke.scm \
	geda/object.scm \
	geda/page.scm \
	geda/attrib.scm \
	geda/deprecated.scm \
	geda/deprecated-config.scm \
	geda/os.scm \
	geda/config.scm \
	geda/log.scm \
	geda/library.scm \
	gschem/action.scm \
	gschem/attrib.scm \
	gschem/builtins.scm \
	gschem/gschemdoc.scm \
	gschem/hook.scm \
	gschem/keymap.scm \
	gschem/selection.scm \
	gschem/symbol/check.scm \
	gschem/util.scm \
	gschem/window.scm \
	gschem/deprecated.scm \
	lepton/attrib.scm \
	lepton/autoplace.scm \
	lepton/bounds.scm \
	lepton/color-map.scm \
	lepton/config.scm \
	lepton/gettext.scm \
	lepton/eval.scm \
	lepton/ffi.scm \
	lepton/ffi/boolean.scm \
	lepton/ffi/check-args.scm \
	lepton/ffi/glib.scm \
	lepton/ffi/gobject.scm \
	lepton/ffi/lff.scm \
	lepton/ffi/lib.scm \
	lepton/ffi/sch2pcb.scm \
	lepton/ffi/undo.scm \
	lepton/file-system.scm \
	lepton/gerror.scm \
	lepton/init.scm \
	lepton/library.scm \
	lepton/library/component.scm \
	lepton/log.scm \
	lepton/log-rotate.scm \
	lepton/object.scm \
	lepton/object/foreign.scm \
	lepton/object/text.scm \
	lepton/object/type.scm \
	lepton/option.scm \
	lepton/os.scm \
	lepton/page.scm \
	lepton/page/foreign.scm \
	lepton/rc.scm \
	lepton/repl.scm \
	lepton/srfi-37.scm \
	lepton/toplevel.scm \
	lepton/toplevel/foreign.scm \
	lepton/version.scm \
	lepton/legacy-config/keylist.scm \
	lepton/legacy-config.scm \
	netlist.scm \
	netlist/attrib/compare.scm \
	netlist/attrib/refdes.scm \
	netlist/backend-getopt.scm \
	netlist/backend.scm \
	netlist/config.scm \
	netlist/deprecated.scm \
	netlist/duplicate.scm \
	netlist/error.scm \
	netlist/hierarchy.scm \
	netlist/mode.scm \
	netlist/net.scm \
	netlist/option.scm \
	netlist/package-pin.scm \
	netlist/package.scm \
	netlist/partlist.scm \
	netlist/partlist/common.scm \
	netlist/port.scm \
	netlist/schematic-component.scm \
	netlist/schematic-connection.scm \
	netlist/schematic-port.scm \
	netlist/schematic.scm \
	netlist/schematic/toplevel.scm \
	netlist/subschematic.scm \
	netlist/subschematic-connection.scm \
	netlist/verbose.scm \
	sch2pcb/element.scm \
	sch2pcb/format.scm \
	sch2pcb/insert.scm \
	sch2pcb/lookup.scm \
	schematic/action.scm \
	schematic/action-mode.scm \
	schematic/action/copy.scm \
	schematic/action/delete.scm \
	schematic/action/edit.scm \
	schematic/action/rotate.scm \
	schematic/attrib.scm \
	schematic/buffer.scm \
	schematic/builtins.scm \
	schematic/callback.scm \
	schematic/callback/cancel.scm \
	schematic/canvas.scm \
	schematic/canvas/foreign.scm \
	schematic/dialog.scm \
	schematic/dialog/autonumber.scm \
	schematic/dialog/file-select.scm \
	schematic/dialog/multiattrib.scm \
	schematic/dialog/new-text.scm \
	schematic/dialog/slot-edit.scm \
	schematic/doc.scm \
	schematic/event.scm \
	schematic/ffi.scm \
	schematic/ffi/gtk.scm \
	schematic/gtk/helper.scm \
	schematic/gui/keymap.scm \
	schematic/gui/stroke.scm \
	schematic/hook.scm \
	schematic/keymap.scm \
	schematic/menu.scm \
	schematic/mouse-pointer.scm \
	schematic/netlist.scm \
	schematic/pcb.scm \
	schematic/precompile.scm \
	schematic/preview-widget.scm \
	schematic/rc.scm \
	schematic/refdes.scm \
	schematic/repl.scm \
	schematic/selection.scm \
	schematic/sellock.scm \
	schematic/symbol/check.scm \
	schematic/toolbar.scm \
	schematic/util.scm \
	schematic/undo.scm \
	schematic/viewport/foreign.scm \
	schematic/window.scm \
	schematic/window/foreign.scm \
	schematic/window/global.scm \
	schematic/window/list.scm \
	symbol/blame.scm \
	symbol/check.scm \
	symbol/check/alignment.scm \
	symbol/check/arc.scm \
	symbol/check/attrib.scm \
	symbol/check/box.scm \
	symbol/check/bus.scm \
	symbol/check/circle.scm \
	symbol/check/component.scm \
	symbol/check/connection.scm \
	symbol/check/duplicate.scm \
	symbol/check/entity-pin.scm \
	symbol/check/forbidden.scm \
	symbol/check/line.scm \
	symbol/check/log.scm \
	symbol/check/net.scm \
	symbol/check/net-attrib.scm \
	symbol/check/obsolete.scm \
	symbol/check/path.scm \
	symbol/check/picture.scm \
	symbol/check/pin.scm \
	symbol/check/pin-attrib.scm \
	symbol/check/primitive.scm \
	symbol/check/slot.scm \
	symbol/check/text.scm \
	symcheck/check.scm \
	symcheck/option.scm \
	symcheck/report.scm

nobase_scmdata_DATA = lepton/m4.scm

TESTS = \
	unit-tests/backend-spice-noqsi.scm \
	unit-tests/geda-attrib-basic.scm \
	unit-tests/geda-config.scm \
	unit-tests/geda-deprecated.scm \
	unit-tests/geda-object-arc.scm \
	unit-tests/geda-object-bounds.scm \
	unit-tests/geda-object-box.scm \
	unit-tests/geda-object-circle.scm \
	unit-tests/geda-object-component.scm \
	unit-tests/geda-object-connections.scm \
	unit-tests/geda-object-copy.scm \
	unit-tests/geda-object-embedded.scm \
	unit-tests/geda-object-fill.scm \
	unit-tests/geda-object-line.scm \
	unit-tests/geda-object-path.scm \
	unit-tests/geda-object-picture.scm \
	unit-tests/geda-object-selectable.scm \
	unit-tests/geda-object-stroke.scm \
	unit-tests/geda-object-text.scm \
	unit-tests/geda-object-transform.scm \
	unit-tests/geda-os-basic.scm \
	unit-tests/geda-os-expand-env-variables.scm \
	unit-tests/geda-page-basic.scm \
	unit-tests/geda-page-dirty.scm \
	unit-tests/geda-page-parse-embed-no-component.scm \
	unit-tests/geda-page-parse-garbage-attrib.scm \
	unit-tests/geda-page-parse-line-endings.scm \
	unit-tests/geda-page-parse-ordering.scm \
	unit-tests/geda-page-parse-unterminated-attrib.scm \
	unit-tests/geda-page-string.scm \
	unit-tests/geda-promotable-attribs.scm \
	unit-tests/lepton-attrib-basic.scm \
	unit-tests/lepton-config.scm \
	unit-tests/lepton-file-system.scm \
	unit-tests/lepton-library-component.scm \
	unit-tests/lepton-library-source-library.scm \
	unit-tests/lepton-object-arc.scm \
	unit-tests/lepton-object-bounds.scm \
	unit-tests/lepton-object-box.scm \
	unit-tests/lepton-object-circle.scm \
	unit-tests/lepton-object-component.scm \
	unit-tests/lepton-object-connections.scm \
	unit-tests/lepton-object-copy.scm \
	unit-tests/lepton-object-embedded.scm \
	unit-tests/lepton-object-fill.scm \
	unit-tests/lepton-object-line.scm \
	unit-tests/lepton-object-path.scm \
	unit-tests/lepton-object-picture.scm \
	unit-tests/lepton-object-selectable.scm \
	unit-tests/lepton-object-stroke.scm \
	unit-tests/lepton-object-text.scm \
	unit-tests/lepton-object-type.scm \
	unit-tests/lepton-object-transform.scm \
	unit-tests/lepton-object-wrong.scm \
	unit-tests/lepton-os-basic.scm \
	unit-tests/lepton-os-expand-env-variables.scm \
	unit-tests/lepton-page-basic.scm \
	unit-tests/lepton-page-dirty.scm \
	unit-tests/lepton-page-parse-embed-no-component.scm \
	unit-tests/lepton-page-parse-garbage-attrib.scm \
	unit-tests/lepton-page-parse-line-endings.scm \
	unit-tests/lepton-page-parse-ordering.scm \
	unit-tests/lepton-page-parse-unterminated-attrib.scm \
	unit-tests/lepton-page-pointer.scm \
	unit-tests/lepton-page-string.scm \
	unit-tests/lepton-pin-whichend.scm \
	unit-tests/lepton-promotable-attribs.scm \
	unit-tests/lepton-rc-build-path.scm \
	unit-tests/lepton-toplevel-basic.scm \
	unit-tests/lepton-toplevel-pointer.scm \
	unit-tests/lepton-version.scm \
	unit-tests/netlist-attrib.scm \
	unit-tests/netlist-load-path.scm \
	unit-tests/netlist-partlist.scm \
	unit-tests/sch2pcb-element.scm \
	unit-tests/sch2pcb-insert.scm \
	unit-tests/sch2pcb-lookup.scm

TEST_EXTENSIONS = .scm
# $(srcdir) and $(builddir) are added here and not in
# AM_SCM_LOG_FLAGS below because guile must know where to find
# netlist modules before it runs tests
SCM_LOG_DRIVER = \
	LANG=C \
	abs_top_builddir=$(abs_top_builddir) \
	abs_top_srcdir=$(abs_top_srcdir) \
	$(GUILE) \
	-L $(abs_top_srcdir)/lepton-eda/scheme \
	-L $(abs_top_builddir)/lepton-eda/scheme \
	-L $(abs_top_srcdir)/tools/netlist/scheme \
	-L $(abs_top_builddir)/tools/netlist/scheme \
	--no-auto-compile -e main/with-toplevel -s $(abs_top_srcdir)/lepton-eda/scheme/unit-test.scm

dist_noinst_DATA = \
	unit-test.scm \
	$(TESTS)

if CYGWIN
USE_CYGWIN=t
else
USE_CYGWIN=f
endif !CYGWIN

if ENABLE_GTK3
USE_GTK3=t
else
USE_GTK3=f
endif !ENABLE_GTK3

# Work-around for Debian and its derivatives.
# Example usage: ./configure USE_LDCONFIG=/sbin/ldconfig ...
LIBGLIB := $(shell test -e "$(USE_LDCONFIG)" && $(USE_LDCONFIG) -p | awk '/libglib-2.0.so\./ {print $$1; exit}')
LIBGOBJECT := $(shell test -e "$(USE_LDCONFIG)" && $(USE_LDCONFIG) -p | awk '/libgobject-2.0.so\./ {print $$1; exit}')
LIBGTK2 := $(shell test -e "$(USE_LDCONFIG)" && $(USE_LDCONFIG) -p | awk '/libgtk-x11-2.0.so\./ {print $$1; exit}')
LIBGTK3 := $(shell test -e "$(USE_LDCONFIG)" && $(USE_LDCONFIG) -p | awk '/libgtk-3.so\./ {print $$1; exit}')

lepton/m4.scm: Makefile
	$(MKDIR_P) lepton/; \
	echo '; this file is generated by make(1) (see lepton-eda/scheme/Makefile.am)' > $@.new && \
	echo '(define-module (lepton m4))' >> $@.new && \
	echo '(define-public %lepton-docdir "$(docdir)")' >> $@.new && \
	echo '(define-public %lepton-localedir "$(localedir)")' >> $@.new && \
	echo '(define-public %lepton-bindir "$(bindir)")' >> $@.new && \
	echo '(define-public %m4-command "$(M4)")' >> $@.new && \
	echo '(define-public %m4-use-cygwin #$(USE_CYGWIN))' >> $@.new && \
	echo '(define-public %m4-use-gtk3 #$(USE_GTK3))' >> $@.new && \
	echo '(define-public %m4-liblepton-major $(LIBLEPTON_MAJOR))' >> $@.new && \
	echo '(define-public %m4-libleptonattrib-major $(LIBLEPTONATTRIB_MAJOR))' >> $@.new && \
	echo '(define-public %m4-libleptongui-major $(LIBLEPTONGUI_MAJOR))' >> $@.new && \
	echo '(define-public %m4-liblepton-gettext-domain "$(LIBLEPTON_GETTEXT_DOMAIN)")' >> $@.new && \
	echo '(define-public %ldconfig-libglib "$(LIBGLIB)")' >> $@.new && \
	echo '(define-public %ldconfig-libgobject "$(LIBGOBJECT)")' >> $@.new && \
	echo '(define-public %ldconfig-libgtk2 "$(LIBGTK2)")' >> $@.new && \
	echo '(define-public %ldconfig-libgtk3 "$(LIBGTK3)")' >> $@.new && \
	echo '(define-public %pcb-m4-dir "$(PCBM4DIR)")' >> $@.new && \
	echo '(define-public %pcb-lib-path "$(PCBLIBPATH)")' >> $@.new && \
	if cmp $@ $@.new > /dev/null 2>&1; then \
	  rm $@.new; echo "$@ is unchanged"; \
	else \
	  echo "Recreating $@"; mv $@.new $@; \
	fi


CLEANFILES = \
	unit-tests/dummy.sym \
	unit-tests/dummy.xpm \
	$(nobase_scmdata_DATA)

# To check it all thoroughly, you could add:
# -Wformat -- to test issues with the built-in format() function.
# -Wunused-toplevel -- to test for toplevel exported vars.
# -Wunused-variable -- to test for other unused vars (there are
#  some in (match ...) and other code).

GUILE_WARNINGS = \
	-Warity-mismatch \
	-Wbad-case-datum \
	-Wduplicate-case-datum \
	-Wmacro-use-before-definition \
	-Wshadowed-toplevel \
	-Wunbound-variable \
	-Wunsupported-warning

SOURCES = $(nobase_dist_scmdata_DATA)
GOBJECTS = $(SOURCES:%.scm=%.go)


# This part depends on the configure switch --enable-guild.
if ENABLE_GUILD

$(GOBJECTS): lepton/m4.go

SUFFIXES = .scm .go
.scm.go:
	$(AM_V_GEN) \
	LIBLEPTON="${abs_top_builddir}/liblepton/src/liblepton" \
	LIBLEPTONGUI="${abs_top_builddir}/libleptongui/src/libleptongui" \
	$(GUILD) compile \
	-L . \
	-L $(abs_top_srcdir)/lepton-eda/scheme \
	-L $(abs_top_builddir)/lepton-eda/scheme \
	$(GUILE_WARNINGS) -o "$@" "$<"

nobase_go_DATA = lepton/m4.go $(GOBJECTS)

# Make sure source files are installed first, so that the mtime of
# installed compiled files is greater than that of installed source
# files.  See
# <http://lists.gnu.org/archive/html/guile-devel/2010-07/msg00125.html>
# for details.
guile_install_go_files = install-nobase_goDATA
$(guile_install_go_files): install-nobase_scmdataDATA install-nobase_dist_scmdataDATA

CLEANFILES += lepton/m4.go $(GOBJECTS)

endif
